{% extends "zato/index.html" %}

{% block html_title %}AMQP channels{% endblock %}

{% block "extra_css" %}
    <link rel="stylesheet" type="text/css" href="/static/css/jquery.alerts.css">
{% endblock %}

{% block "extra_js" %}

    {% comment %} jQuery {% endcomment %}
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.tablesorter.min.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.cookie.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.alerts.min.js"></script>

    {% comment %} Common JS {% endcomment %}
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/common.js"></script>

    {% comment %} HTTP Basic Auth {% endcomment %}
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/channel/amqp.js"></script>


    <script nonce="{{ CSP_NONCE }}">
    $.fn.zato.data_table.get_columns = function() {
        return [
            '_numbering',
            '_selection',
            'name',
            '_is_active',
            'def_name',
            'queue',
            'consumer_tag_prefix',
            'pool_size',
            'ack_mode',
            'prefetch_count',
            'service',
            '_edit',
            '_delete',
            'id',
            'is_active',
            'def_id',
            'data_format',
        ]
    }
    </script>

{% endblock %}

{% block "content" %}
<h2 class="zato">AMQP channels</h2>

{% if not zato_clusters %}
    {% include "zato/no-clusters.html" %}
{% else %}

    <div id="user-message-div" style='display:none'><pre id="user-message" class="user-message"></pre></div>

{% include "zato/search-form.html" with page_prompt="Show channels"%}


    {% if cluster_id %}
        <div class='page_prompt' style="clear:left">
            <a href="javascript:$.fn.zato.channel.amqp.create()">Create a new AMQP channel</a>
        </div>


        <div id="markup">
            <table id="data-table">
                <thead>
                    <tr class='ignore'>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                        <th><a href="#">Name</a></th>
                        <th><a href="#">Active</a></th>
                        <th><a href="#">Definition</a></th>
                        <th><a href="#">Queue</a></th>
                        <th><a href="#">Consumer tag prefix</a></th>
                        <th><a href="#">Pool size</a></th>
                        <th><a href="#">Ack mode</a></th>
                        <th><a href="#">Prefetch count</a></th>
                        <th><a href="#">Service</a></th>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                </thead>

                <tbody>
                {% if items %}
                {% for item in items %}
                    <tr class="{% cycle 'odd' 'even' %}" id='tr_{{ item.id }}'>
                        <td class='numbering'>&nbsp;</td>
                        <td class="impexp"><input type="checkbox" /></td>
                        <td>{{ item.name }}</td>
                        <td>{{ item.is_active|yesno:'Yes,No' }}</td>
                        <td>{{ item.def_name }}</td>
                        <td>{{ item.queue }}</td>
                        <td>{{ item.consumer_tag_prefix }}</td>
                        <td>{{ item.pool_size }}</td>
                        <td>{{ item.ack_mode }}</td>
                        <td>{{ item.prefetch_count }}</td>
                        <td><a href="{% url "service-overview" item.service_name %}?cluster={{ cluster_id }}">{{ item.service_name }}</a></td>
                        <td><a href="javascript:$.fn.zato.channel.amqp.edit('{{ item.id }}')">Edit</a></td>
                        <td><a href="javascript:$.fn.zato.channel.amqp.delete_('{{ item.id }}')">Delete</a></td>
                        <td class='ignore item_id_{{ item.id }}'>{{ item.id }}</td>
                        <td class='ignore'>{{ item.is_active }}</td>
                        <td class='ignore'>{{ item.def_id }}</td>
                        <td class='ignore'>{{ item.data_format }}</td>
                    </tr>
                {% endfor %}
                {% else %}
                    <tr class='ignore'>
                        <td colspan='16'>No results</td>
                    </tr>
                {% endif %}

                </tbody>
            </table>
        </div>

{% include "zato/paginate/action-panel.html" %}

        <div id="create-div" class='data-popup ignore'>
            <div class="bd">
                <form novalidate action="{% url "channel-amqp-create" %}" method="post" id="create-form">
                    <table class="form-data">
                        <tr>
                            <td style="vertical-align:middle;width:20%">Name</td>
                            <td>{{ create_form.name }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Active</td>
                            <td>{{ create_form.is_active }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Definition</td>
                            <td>{{ create_form.def_id }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Queue</td>
                            <td>{{ create_form.queue }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Consumer tag prefix</td>
                            <td>{{ create_form.consumer_tag_prefix }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Ack mode</td>
                            <td>{{ create_form.ack_mode }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Prefetch count</td>
                            <td>{{ create_form.prefetch_count }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Pool size</td>
                            <td>{{ create_form.pool_size }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Service</td>
                            <td>{{ create_form.service }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Data format</td>
                            <td>{{ create_form.data_format }}</td>
                        </tr>

                        <tr>
                            <td colspan="2" style="text-align:right">
                                <input type="submit" value="OK" />
                                <button type='button' onclick='javascript:$.fn.zato.data_table.close(this)'>Cancel</button>
                            </td>
                        </tr>
                    </table>
                    <input type="hidden" id="cluster_id" name="cluster_id" value="{{ cluster_id }}" />
                </form>
            </div>
        </div>

        <div id="edit-div" class='data-popup ignore'>
            <div class="bd">
                <form novalidate action="{% url "channel-amqp-edit" %}" method="post" id="edit-form">
                    <table class="form-data">
                        <tr>
                            <td style="vertical-align:middle;width:20%">Name</td>
                            <td>{{ edit_form.name }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Active</td>
                            <td>{{ edit_form.is_active }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Definition</td>
                            <td>{{ edit_form.def_id }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Queue</td>
                            <td>{{ edit_form.queue }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Consumer tag prefix</td>
                            <td>{{ edit_form.consumer_tag_prefix }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Ack mode</td>
                            <td>{{ edit_form.ack_mode }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Prefetch count</td>
                            <td>{{ edit_form.prefetch_count }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Pool size</td>
                            <td>{{ edit_form.pool_size }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Service</td>
                            <td>{{ edit_form.service }}</td>
                        </tr>

                        <tr>
                            <td style="vertical-align:middle">Data format</td>
                            <td>{{ edit_form.data_format }}</td>
                        </tr>

                        <tr>
                            <td colspan="2" style="text-align:right">
                                <input type="submit" value="OK" />
                                <button type='button' onclick='javascript:$.fn.zato.data_table.close(this)'>Cancel</button>
                            </td>
                        </tr>
                    </table>
                    <input type="hidden" id="id_edit-cluster_id" name="cluster_id" value="{{ cluster_id }}" />
                    <input type="hidden" id="id_edit-id" name="id" />
                </form>
            </div>
        </div>
    {% endif %}


{% endif %}{% comment %}not zato_clusters{% endcomment %}

{% endblock %}
